# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     listFile
   Description : 读取指定目录下特定类型的文件名列表
   Author :       pc
   date：          2018/1/7
-------------------------------------------------
   Change Activity:
                   2018/1/7:
-------------------------------------------------
"""
__author__ = 'pc'


def IsSubString(SubStrList, Str):
    """
    #判断字符串Str是否包含序列SubStrList中的每一个子字符串
    #>>>SubStrList=['F','EMS','txt']
    #>>>Str='F06925EMS91.txt'
    #>>>IsSubString(SubStrList,Str)#return True (or False)
    """
    flag = True
    for substr in SubStrList:
        if not (substr in Str):
            flag = False

    return flag


# ~ #----------------------------------------------------------------------
def GetFileList(FindPath, FlagStr=[], fileType=""):
    """
    #获取目录中指定的文件名
    #>>>FlagStr=['F','EMS','txt'] #要求文件名称中包含这些字符
    #>>>FileList=GetFileList(FindPath,FlagStr) #
    """

    fileType = "." + fileType
    import os
    FileListTotal = []
    FileList = []
    nameList = []
    FileNames = os.listdir(FindPath)
    if (len(FileNames) > 0):
        for fn in FileNames:
            if (len(FlagStr) > 0):
                if (fileType == os.path.splitext(fn)[1]):
                    # 返回指定类型的文件名
                    if (IsSubString(FlagStr, fn)):
                        FileList.append(fn)

                    # 判断文件名种类
                    if (fn.split("_")[0] not in nameList):
                        nameList.append(fn.split("_")[0])
            else:
                # 默认直接返回所有文件名
                fullfilename = os.path.join(FindPath, fn)
                FileList.append(fullfilename)

    # 对文件名排序
    if (len(FileList) > 0):
        FileList.sort()

    # FileListTotal.append(FileList)
    # FileListTotal.append(nameList)

    return FileList
    # return FileListTotal


if __name__ == '__main__':
    exePath = "E:\src\pycharm\calBill\excelFile"
    fileList = GetFileList(exePath, "123", "xls")
    print(fileList)
